import re

from prutils.pr_string import get_re_first_subs
from prutils.pr_utils import read_file, write_file


def file_replace_str(file_path, pattern, repl, flags=0):
    text = read_file(file_path, "rb").decode("utf-8")
    text = re.sub(pattern, repl, text, 0, flags)
    write_file(file_path, text.encode("utf-8"), "wb")

config_text = read_file("config.py", "rb").decode("utf-8")
v1, v2, v3 = get_re_first_subs(r"version='(\d+)\.(\d+)\.(\d+)'", config_text)
v3 = str(int(v3) + 1)
new_ver = "version='%s.%s.%s'" % (v1, v2, v3)
file_replace_str("config.py", r"version='\d+\.\d+\.\d+'", new_ver)
